package net.awpspace.mobile.management.house;

import java.util.Vector;

import javax.microedition.midlet.MIDlet;

import net.awpspace.mobile.form.BaseForm;

import com.sun.lwuit.List;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;

public class MemberViewer extends BaseForm {

	private List list;
	private Vector data;	
	public MemberViewer(MIDlet app, BaseForm parent) {
		super(app, parent);
		// TODO Auto-generated constructor stub
		setTitle("Member View");
		setTransitionInAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_HORIZONTAL, true, 1200));
		setTransitionOutAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_HORIZONTAL, true, 1200));
		
		list = new List();
//		list.setFocusable(true);
		list.setSmoothScrolling(true);
//		list.setSelectedIndex(0);
		list.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				itemStateChanged();
			}
		});
		data = Persistence.getInstance().getData();
		createComponent();
		
	}
	
	protected void itemStateChanged() {
		// TODO Auto-generated method stub		
		int index = list.getSelectedIndex();
		AudioManager.getInstance().play(AudioManager.BUTTON);
		new DetailsMemberViewer(app, this, (HouseMember)(data.elementAt(index))).show();
	}

	public void createComponent(){
		for(int i = 0; i < data.size(); i++){
			list.addItem(((HouseMember)data.elementAt(i)).getName());
		}
		addComponent(list);
	}
		
	protected void processCommand(ActionEvent e) {
		// TODO Auto-generated method stub

	}

}
